-- revive2
-- created by zhuangsl
-- 死亡概率复活恢复血量N

return {
    apply = function(prop, baseValue)
        -- baseValue期望是最大血量，返回的是恢复的血量
        return math.modf(baseValue + prop[2]);
    end,

    -- 死亡触发
    trigger = function(who, prop, arg)
        -- 概率触发
        local rand = DungeonM.getRandSeed("revive2") % 1000;
        if (rand > prop[3]) then
            return;
        end

        local maxHp = who:getMaxHp();
        local hp = tonumber(prop[2]);
        if hp > maxHp then
            hp = maxHp;
        end
        local baseHp = who.dbase:query("hp", 0);

        -- 需要滤掉属性加成的部分
        -- hp = hp - (who:queryAttrib("hp") - baseHp);

        -- 设置血量
        who:addAttrib("hp", hp - who:queryAttrib("hp"), "revive");
        -- who.dbase:set("hp", hp);

        -- 清除负面状态
        CombatStatusM.reviveClean(who);

        return who:getHp() > 0;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;
        local rate = math.modf(prop[3] / 10);

        desc = string.gsub(desc, "{0}", prop[2]);

        desc = string.gsub(desc, "{1}", rate);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
